part of base.widgets;

class ToolBar extends AppBar {
  ToolBar(String title, //页面标题，必须
      {Key? key,
      String? subTitle, //页面子标提
      bool isCenterTitle = true, //是否中间居中，默认中间居中，参数可选
      final List<Widget>? actions, //右边部分，可能存放图标，文字等，可能还有点击事件，参数可选
      final hasBack = true,
      final PreferredSizeWidget? bottom,
      final backIcon = const Icon(
        Icons.arrow_back_ios,
        color: Colors.black,
      ), //左边返回箭头图标，默认是<，可自定义，，参数可选也可以是文字
      final String rightText = '', //右边文字，参数可选
      final GestureTapCallback? rightCallback, //右边文字或者图标的点击函数，参数可选
      final TextStyle? subTitleStyle,
      final double? toolbarHeight,
      SystemUiOverlayStyle systemOverlayStyle = SystemUiOverlayStyle.dark})
      : super(
          key: key,
          titleSpacing: NavigationToolbar.kMiddleSpacing,
          title: Column(
            mainAxisAlignment: isCenterTitle
                ? MainAxisAlignment.center
                : MainAxisAlignment.start,
            crossAxisAlignment: isCenterTitle
                ? CrossAxisAlignment.center
                : CrossAxisAlignment.start,
            children: <Widget>[
              Text(
                title,
                style: KTheme.appBarTitleStyle,
              ),
              if (subTitle != null)
                Text(
                  subTitle,
                  style: subTitleStyle ?? KTheme.appBarSubTitleStyle,
                )
            ],
          ),
          automaticallyImplyLeading: hasBack,
          leading: !hasBack
              ? null
              : IconButton(icon: backIcon, onPressed: () => Get.back()),
          centerTitle: isCenterTitle,
          bottom: bottom,
          toolbarHeight: toolbarHeight,
          systemOverlayStyle: systemOverlayStyle,
          actions: actions ??
              <Widget>[
                Padding(
                  padding: EdgeInsets.only(right: 10.0),
                  child: Center(
                    child: GestureDetector(
                      onTap: rightCallback,
                      child: Text(rightText, style: KTheme.appBarMenuStyle),
                    ),
                  ),
                ),
              ],
        );

  ToolBar.noBack(String title, //页面标题，必须
      {Key? key,
      String? subTitle, //页面子标提
      bool isCenterTitle = true, //是否中间居中，默认中间居中，参数可选
      final List<Widget>? actions, //右边部分，可能存放图标，文字等，可能还有点击事件，参数可选
      final double? toolbarHeight,
      final String rightText = '', //右边文字，参数可选
      final rightCallback, //右边文字或者图标的点击函数，参数可选
      final PreferredSizeWidget? bottom,
      SystemUiOverlayStyle systemOverlayStyle = SystemUiOverlayStyle.dark,
      final TextStyle? subTitleStyle})
      : super(
          key: key,
          titleSpacing: NavigationToolbar.kMiddleSpacing,
          bottom: bottom,
          systemOverlayStyle: systemOverlayStyle,
          toolbarHeight: toolbarHeight,
          title: Column(
            mainAxisAlignment: isCenterTitle
                ? MainAxisAlignment.center
                : MainAxisAlignment.start,
            crossAxisAlignment: isCenterTitle
                ? CrossAxisAlignment.center
                : CrossAxisAlignment.start,
            children: <Widget>[
              Text(
                title,
                style: KTheme.appBarSubTitleStyle,
              ),
              if (subTitle != null)
                Text(
                  subTitle,
                  style: subTitleStyle ?? KTheme.appBarSubTitleStyle,
                )
            ],
          ),
          automaticallyImplyLeading: false,
          centerTitle: isCenterTitle,
          actions: actions ??
              <Widget>[
                Padding(
                  padding: EdgeInsets.only(right: 10.0),
                  child: Center(
                    child: GestureDetector(
                      onTap: () {
                        rightCallback();
                      },
                      child: Text(rightText, style: KTheme.appBarMenuStyle),
                    ),
                  ),
                ),
              ],
        );

  ToolBar.custom(final Widget widget,
      {Key? key,
      final List<Widget>? actions, //右边部分，可能存放图标，文字等，可能还有点击事件，参数可选
      final double? toolbarHeight,
      final PreferredSizeWidget? bottom,
      final bool automaticallyImplyLeading = true,
      SystemUiOverlayStyle systemOverlayStyle = SystemUiOverlayStyle.dark})
      : super(
          key: key,
          elevation: 0,
          titleSpacing: NavigationToolbar.kMiddleSpacing,
          bottom: bottom,
          toolbarHeight: toolbarHeight,
          systemOverlayStyle: systemOverlayStyle,
          title: widget,
          automaticallyImplyLeading: automaticallyImplyLeading,
          actions: actions,
        );

  ///
  @override
  Size get preferredSize => Size.fromHeight(kToolbarHeight);
}
